﻿using System.Collections.ObjectModel;
using System.Linq;
using StartupSolution.Models;

namespace StartupSolution.ViewModel
{
    public class OrganizationViewModel
    {
        public OrganizationViewModel()
        {
            this.Employees = new ObservableCollection<EmployeeModel>() { CreateTree(3, 3, "1") };
        }

        public ObservableCollection<EmployeeModel> Employees { get; set; }

        private EmployeeModel CreateTree(int depth, int nodesPerLevel, string id)
        {
            EmployeeModel employee = new EmployeeModel();
            employee.Name = "Employee";
            employee.Id = id;

            if (depth > 1)
            {
                employee.Subordinates = new ObservableCollection<EmployeeModel>(
                        from index in Enumerable.Range(1, nodesPerLevel)
                        select CreateTree(
                            depth - 1,
                            nodesPerLevel,
                            (employee.Id + index).ToString()));
            }

            return employee;
        }
    }
}
